<?php


namespace XinYaTable\Forms\Models;



/**
 * Class EloquentFormCustomView
 *
 * @package XinYaTable\Forms\Models
 */
class EloquentFormCustomView extends BaseModel
{
    const DEFAULT_CUSTOM_VIEW_FIELDS = ['id', 'field_id', 'field_name', 'field_type', 'title', 'width', 'order', 'sortable', 'resizable', 'editable', 'display_format'];
    /**
     * `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
     * `field_id` int(11) NOT NULL DEFAULT '0' COMMENT '字段id',
     * `field_name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '字段名称',
     * `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '显示标题',
     * `form_id` int(11) NOT NULL DEFAULT '0' COMMENT '表单id',
     * `width` int(11) NOT NULL DEFAULT '0' COMMENT '显示列宽，单位px',
     * `uid` int(11) NOT NULL DEFAULT '0' COMMENT '用户编号 -1 为系统默认显示列',
     * `is_system` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否为系统默认显示列',
     * `order` int(11) NOT NULL DEFAULT '1' COMMENT '显示排序 升序',
     * `create_uid` int(11) NOT NULL DEFAULT '0',
     * `update_uid` int(11) NOT NULL DEFAULT '0',
     * `created_at` bigint(20) NOT NULL DEFAULT '0',
     * `updated_at` bigint(20) NOT NULL DEFAULT '0',
     * `action_type` tinyint(4) NOT NULL DEFAULT '1',
     */
    protected $table = 'sys_form_custom_view';

    /**
     * @var array
     */
    protected $fillable
        = [
            'field_id',
            'field_name',
            'field_type',
            'title',
            'form_id',
            'width',
            'uid',
            'is_system',
            'order',
            'sortable',
            'resizable',
            'create_uid',
            'update_uid',
            'created_at',
            'updated_at',
            'action_type',
            'display_format',
            'editable'
        ];

    /**
     * @param $query
     *
     * @return mixed
     */
    public function scopeListFields($query)
    {
        return $query->select(self::DEFAULT_CUSTOM_VIEW_FIELDS);
    }

    /**
     * @param     $query
     * @param int $formId
     *
     * @return mixed
     */
    public function scopeSystemView($query, int $formId)
    {
        return $query->where('form_id', $formId)->where('is_system', 1);
    }

    /**
     * @param     $query
     * @param int $formId
     * @param int $uid
     *
     * @return mixed
     */
    public function scopeCustomView($query, int $formId, int $uid)
    {
        return $query->where('form_id', $formId)->where('uid', $uid);
    }

}